<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>this</title>
</head>

<body>
    <script>
        function fn1() {
            console.log(this)
        }
        fn1() // window
        fn1.call({ x: 100 }) //{x:100}
        const fn2 = fn1.bind({ x: 200 });
        // bind 会返回一个新的函数执行，即这个fn2
        fn2() //{x:200}

        const zhangsan = {
            name: '张三',
            sayHi() {
                // this 即当前对象
                console.log(this);
            },
            wait() {
                setTimeout(() => {
                    // this 即当前对象
                    console.log(this);
                });
            },
        }

        const zhangsan = {
            name: '张三',
            sayHi() {
                // this 即当前对象
                console.log(this);
            },
            wait() {
                setTimeout(function () {
                    // this === window
                    console.log(this);
                });
            },
        }



    </script>
</body>

</html>